package com.msun.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.msun.constant.MessageConstant;
import com.msun.entity.PageResult;
import com.msun.entity.QueryPageBean;
import com.msun.entity.Result;
import com.msun.pojo.Plan;
import com.msun.pojo.Questionnaire;
import com.msun.service.PlanService;
import com.msun.service.QuestionnaireService;
import org.springframework.web.bind.annotation.*;

/**
 * 问卷管理
 */

@RestController
@RequestMapping("/questionnaire")
public class QuestionnaireController {
    @Reference//查找服务
    private QuestionnaireService questionnaireService;

   ///新增检查项
    @RequestMapping("/add")
    public Result add(@RequestBody Questionnaire questionnaire){
        try{
            questionnaireService.add(questionnaire);
        }catch (Exception e){
            e.printStackTrace();
            //服务调用失败
            return new Result(false, "表单新增失败");
        }
        return  new Result(true,"表单新增成功");
    }
    ///新增检查项
    @RequestMapping("/edit")
    public Result edit(@RequestBody Questionnaire questionnaire){
        try{
            questionnaireService.edit(questionnaire);
        }catch (Exception e){
            e.printStackTrace();
            //服务调用失败
            return new Result(false, "表单修改失败");
        }
        return  new Result(true,"表单修改成功");
    }
    ///新增检查项
    @RequestMapping("/del/{id}")
    public Result add(@PathVariable Integer id){
        try{
            questionnaireService.del(id);
        }catch (Exception e){
            e.printStackTrace();
            //服务调用失败
            return new Result(false, "表单删除失败");
        }
        return  new Result(true,"表单删除成功");
    }
    //分页查询
    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = questionnaireService.pageQuery(queryPageBean);
        return pageResult;
    }




}
